/*
 * 文件上传
 *
 * @Author:    zhoujk
 * @Date:      2022-09-03 21:55:25
 */
import { postRequest, getRequest, getDownload, postUpload } from '/@/lib/axios'

export const fileApi = {
  // 文件上传 @author 卓大
  uploadUrl: '/support/file/upload',
  uploadFile: (param, folder) => {
    return postRequest(`/support/file/upload?folder=${folder}`, param)
  },

  /**
   * 分页查询  @author 卓大
   */
  queryPage: (param) => {
    return postRequest('/support/file/queryPage', param)
  },

  /**
   * 获取文件URL：根据fileKey @author 胡克
   */
  getUrl: (fileKey) => {
    return getRequest(`/support/file/getFileUrl?fileKey=${fileKey}`)
  },

  /**
   * 下载文件流（根据fileKey） @author 胡克
   */
  downLoadFile: (fileKey) => {
    return getDownload('/support/file/downLoad', { fileKey })
  },

  download: () => {
    return postRequest('/b-file/file/download')
  },
}

export const uploadFileOther = async (param) => {
  return postUpload('/b-file/file/upload', param, {
    headers: {
      'Content-Type': 'application/json;charset=UTF-8', // 发送 JSON 数据
      authorization: 'authorization-text', // 动态设置授权头
    },
  })
}
